import {
  get
} from '../../../utils/request'
import {
  APIS
} from '../../../utils/api'

Component({
  properties: {
    title: {
      type: String,
      value: ''
    },
    needBack: {
      type: Boolean,
      value: true
    },
    isWhite: {
      type: Boolean,
      value: false
    },
    needBg: {
      type: Boolean,
      value: true
    },
    needShop: {
      type: Boolean,
      value: false
    },
    isNoStorage: {
      type: Boolean,
      value: false
    }
  },
  attached() {
    this.getShopData();
  },
  ready() {
    let sysInfo = wx.getSystemInfoSync();
    let navBarHeight = sysInfo.statusBarHeight;
    this.setData({
      navBarHeight
    })
  },
  data: {
    navBarHeight: 0,
    currentIndex: 1,
    shopList: [],
    shopArray: [],
    shopIds: []
  },
  methods: {
    handleBack() {
      wx.navigateBack({
        delta: 1
      })
    },
    getShopData() {
      let shopList = wx.getStorageSync('shopList');
      let currShop = wx.getStorageSync('currShop');
      this.setData({
        shopList,
        shopArray: shopList.map(v => v.name),
        shopIds: shopList.map(v => v.id),
        currentIndex: shopList.findIndex(v => v.id === currShop.id)
      })
    },
    bindChangeShop(e) {
      const index = e.detail.value;
      this.setData({
        currentIndex: index,
      });
      if (!this.data.isNoStorage) {
        wx.setStorageSync('currShop', this.data.shopList[index]);
      }
      this.triggerEvent('currShop', this.data.shopList[index]);
    }
  }
})